﻿using AE_BEPUPhysics_Addition;
using GameConfig;
using GameProtocol;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GameLogic
{
    public class ShipSlotControl
    {
        ShipControl m_ShipControl;
        SlotDesignData m_SlotDesignData;
        SlotConfigData m_SlotConfigData;

        WeaponControl m_WeaponControl;

        BEPUutilities.Vector2 m_AimPos;

        public int Group { get { return m_SlotConfigData.Group; } }

        public SlotDesignData SlotDesignData { get => m_SlotDesignData; set => m_SlotDesignData = value; }

        public ShipSlotControl(ShipControl shipControl, SlotDesignData slotData)
        {
            m_ShipControl = shipControl;
            m_SlotDesignData = slotData;
        }
        #region 开放接口
        public void Update()
        {
            m_WeaponControl.Update();
        }
        public void Init(SlotConfigData configData)
        {
            m_SlotConfigData = configData;

            m_WeaponControl = new WeaponControl(m_SlotConfigData.EquipmentID, this);
        }
        public void Clean()
        {
            m_WeaponControl.Clean();
        }
        public Influence GetShipInfluence()
        {
            return m_ShipControl.Influence;
        }
        public ShipView GetShipView()
        {
            return m_ShipControl.ShipView;
        }
        public BaseVolumnBaseCollider GetShipCollider()
        {
            return m_ShipControl.Collider;
        }
        public ShipControl GetShipControl()
        {
            return m_ShipControl;
        }
        public BEPUutilities.Vector3 GetShipPosition()
        {
            return m_ShipControl.GetLogicPosition();
        }
        public BEPUutilities.Quaternion GetShipRotation()
        {
            return m_ShipControl.GetLogicRotation();
        }
        bool m_FireFlag = false;
        public void SetFire(bool fire)
        {
            m_FireFlag = fire;
        }
        public void AimPos(BEPUutilities.Vector2 pos)
        {
            m_AimPos = pos;
        }

        public void DoLogic()
        {
            if (m_WeaponControl != null)
                m_WeaponControl.DoLogic();
            if(m_FireFlag)
                DoFire();
            DoAimPos();
        }
        #endregion

        #region 私有接口
        void DoFire()
        {
            m_FireFlag = false;
            if(m_WeaponControl != null)
                m_WeaponControl.Fire();
        }
        void DoAimPos()
        {
            if (m_WeaponControl == null)
                return;
            m_WeaponControl.AimPos(m_AimPos);
        }
        #endregion
    }
}
